using System;
using System.Collections.Generic;
using UnityEngine;

public class PackagePage : MonoBehaviour
{
	public GameObject this[int index]
	{
		get
		{
			if (this.levels.Count == 0)
			{
				return null;
			}
			if (index >= this.levels.Count)
			{
				return null;
			}
			return this.levels[index];
		}
	}

	public void Reset(tk2dUIScrollPage scrollPage)
	{
		this.packageWidth = scrollPage.packageWidth;
		this.packageHeight = scrollPage.packageHeight;
		Vector2 levelSize = scrollPage.levelSize;
		Vector2 packageMargin = scrollPage.packageMargin;
		Vector2 packageOffset = scrollPage.packageOffset;
		int num = this.packageWidth * this.packageHeight;
		if (this.levels.Count < num)
		{
			int num2 = num - this.levels.Count;
			for (int i = 0; i < num2; i++)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(scrollPage.levelPrefab);
				gameObject.transform.parent = base.transform;
				this.levels.Add(gameObject);
			}
		}
		float num3 = (levelSize.x * (float)this.packageWidth + packageMargin.x * (float)(this.packageWidth - 1)) * 0.5f;
		float num4 = (levelSize.y * (float)this.packageHeight + packageMargin.y * (float)(this.packageHeight - 1)) * 0.5f;
		for (int j = 0; j < this.packageHeight; j++)
		{
			for (int k = 0; k < this.packageWidth; k++)
			{
				GameObject gameObject2 = this.levels[j * this.packageWidth + k];
				float x = (float)k * (levelSize.x + packageMargin.x) - num3 + levelSize.x * 0.5f + packageOffset.x;
				float y = (float)j * -(levelSize.y + packageMargin.y) + num4 - levelSize.y * 0.5f + packageOffset.y;
				Vector3 localPosition = new Vector3(x, y, -1f);
				gameObject2.transform.localPosition = localPosition;
			}
		}
	}

	private List<GameObject> levels = new List<GameObject>();

	private int packageWidth;

	private int packageHeight;
}
